package com.hx.myblog3.control.admin;


import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hx.myblog3.entity.User;
import com.hx.myblog3.service.UserService;

@Controller
public class UserConrtol {
     @Autowired
     private UserService us;
     
     @RequestMapping("/userlogin")
     @ResponseBody
     public String login(@RequestParam("name") String name,@RequestParam("pass") String pass,HttpSession session) {
    	 User user=us.loginCheck(name, pass);
    	 System.out.println(user);
 		if(user==null){
 			return "登录失败";
 		}
 		else{
 			session.setAttribute("userinfo", user);
 			return "登录成功";
 		}
	}
     
     @RequestMapping("/admin/userinfo")
     @ResponseBody
     public User userMessage(HttpSession session) {
		return (User)session.getAttribute("userinfo");
	}
     
     @RequestMapping("/admin/esc")
     @ResponseBody
     public String esc(HttpSession session){
    	 session.removeAttribute("userinfo");
    	 return "退出成功！";
     }
     
     
}
